package com.wnhz.work.yz.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.wnhz.work.yz.R;
import com.wnhz.work.yz.base.BaseRVAdapter;
import com.wnhz.work.yz.base.BaseViewHolder;
import com.wnhz.work.yz.base.RecycleViewDivider;
import com.wnhz.work.yz.bean.IndustryTitleBean;

import java.util.ArrayList;

public class DialogIndustryActivity extends Activity {
    private int cateid = -1, orderid = -1, areaid = -1;
    ArrayList<IndustryTitleBean.InfoEntity> info = new ArrayList<>();
    ArrayList<IndustryTitleBean.InfoEntity.CateEntity> cate = new ArrayList<>();
    private int position;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_industry_sort);
        info = (ArrayList<IndustryTitleBean.InfoEntity>) getIntent().getSerializableExtra("info");
        cate = (ArrayList<IndustryTitleBean.InfoEntity.CateEntity>) getIntent().getSerializableExtra("cate");
        position = getIntent().getIntExtra("position", 0);
        cateid = getIntent().getIntExtra("cateid", -1);
        orderid = getIntent().getIntExtra("orderid", -1);
        areaid = getIntent().getIntExtra("areaid", -1);
        final RecyclerView min_title_select = (RecyclerView) findViewById(R.id.min_title_select);
        min_title_select.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
        ((TextView) findViewById(R.id.title_text)).setText(info.get(position).getName());
        RecycleViewDivider recycleViewDivider = new RecycleViewDivider(this, LinearLayout.HORIZONTAL
                , getResources().getDimensionPixelSize(R.dimen.line_h), getResources().getColor(R.color.line_color));
        min_title_select.addItemDecoration(recycleViewDivider);

        findViewById(R.id.cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        min_title_select.setAdapter(new BaseRVAdapter(this, cate) {
            @Override
            public int getLayoutId(int viewType) {
                return R.layout.item_min_title_select;
            }

            @Override
            public void onBind(BaseViewHolder holder2, final int position2) {
                final TextView select = holder2.getTextView(R.id.item_min_select_text);

                switch (position) {
                    case 0:
//                                        Log.e("---" + cate.get(position).getCateid() + "---", "" + cateid);
                        if (cate.get(position2).getCateid().equals(cateid + "")) {
                            select.setTextColor(getResources().getColor(R.color.main_color));
                        } else {
                            select.setTextColor(getResources().getColor(R.color.text));
                        }
                        break;
                    case 1:
                        if (cate.get(position2).getCateid().equals(orderid + "")) {
                            select.setTextColor(getResources().getColor(R.color.main_color));
                        } else {
                            select.setTextColor(getResources().getColor(R.color.text));
                        }
                        break;
                    case 2:
                        if (cate.get(position2).getCateid().equals(areaid + "")) {
                            select.setTextColor(getResources().getColor(R.color.main_color));
                        } else {
                            select.setTextColor(getResources().getColor(R.color.text));
                        }
                        break;
                }

                holder2.setTextView(R.id.item_min_select_text, cate.get(position2).getCatename());
                select.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {

                        //根据你点击的第几个，然后判断
                        switch (position) {
                            case 0:
                                cateid = Integer.parseInt(info.get(position).getCate().get(position2).getCateid());
                                break;
                            case 1:
                                orderid = Integer.parseInt(info.get(position).getCate().get(position2).getCateid());
                                break;
                            case 2:
                                areaid = Integer.parseInt(info.get(position).getCate().get(position2).getCateid());
                                break;
                        }
                        //设置选择哪个换字上去
//                                        info.get(position).setName(info.get(position).getCate().get(position2).getCatename());
//                                        adapter5.notifyDataSetChanged();
//                        upload2Content();
//                                        Drawable drawable = getResources().getDrawable(R.mipmap.list_pulldown_iocn3x_right);
//                                        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight()); //设置边界
//                                        holder.getTextView(R.id.tv_item_title).setCompoundDrawables(null, null, drawable, null);

                        Intent intent = new Intent();
                        intent.putExtra("cateid", cateid);
                        intent.putExtra("orderid", orderid);
                        intent.putExtra("areaid", areaid);
                        setResult(RESULT_OK, intent);
                        finish();
                    }
                });
            }

        });
    }
}
